package com.boot.redisson.exception.handler;

import com.boot.web.exception.ModuleExceptionHandler;
import com.boot.web.http.HttpModel;
import com.boot.web.http.Status;
import lombok.EqualsAndHashCode;
import org.redisson.client.RedisException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

/**
 * @author 霜寒 <1621856595@qq.com>
 * @description Redisson 错误的处理器
 * @date 2020/4/2 23:58
 **/
@Component
@EqualsAndHashCode
public class RedisExceptionHandler implements ModuleExceptionHandler {
    @Override
    public boolean support(Exception e) {
        return e instanceof RedisException;
    }

    @Override
    public int order() {
        return 90;
    }

    @Override
    public ResponseEntity<HttpModel<Object>> handle(Exception e) {
        return new ResponseEntity<>(
                HttpModel.<Object>builder().code(Status.DATABASE_ERROR.getStatus()).msg(Status.DATABASE_ERROR.getDescription() + " , " + "Redis 错误：" + e.getMessage()).build(),
                HttpStatus.SERVICE_UNAVAILABLE);
    }
}
